Skip to content

Print a Rust date the way it is read, so a year before 0 reads back - #1107

Merged
jeremy merged 1 commit into
mainfrom
fix/date-display-round-trip
Nov 19, 2026
Merged

jeremy merged 1 commit into
mainfrom
fix/date-display-round-trip

Conversation

@jeremy

@jeremy jeremy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1106. jiff's civil::Date Display writes a year before 0 with six digits (-000001-01-01), but Date parses with %Y-%m-%d, which reads at most four. So Date::new(-1, 1, 1) printed, and serialized, as something it couldn't read back. chrono round-tripped it. Copilot found the same thing on the matching hey-sdk change (basecamp/hey-sdk#311).

Display now formats with the same %Y-%m-%d it parses with. For years 0 to 9999 the output is byte-identical to before (checked across 59,997 dates from -9999 to 9999, all of which round-trip). The new every_date_reads_back_what_it_prints test round-trips the calendar's ends, -1 and 0 through both Date::parse and serde.

Neither API sends such dates, so this only matters to a caller building one by hand. It is a patch-level fix to an unreleased change.


Summary by cubic

Fixes date display so a year before 0 prints as something Date can read back. jiff's Display writes a year before 0 with six digits (-000001), which %Y-%m-%d parsing doesn't read, so such a date no longer round-tripped through printing or JSON as it did with chrono.

Display now formats with the same %Y-%m-%d used for parsing; years 0-9999 print byte-identically. A new test round-trips the calendar's ends, years before 0 included, through both Date::parse and serde. Neither API sends such dates, so this only matters when building one by hand.

Written for commit 522cb5f. Summary will update on new commits.

View guided diff Turn on auto-fix

jiff's Display writes a negative year with six digits (-000001), which
the %Y-%m-%d that Date reads does not take, so since #1106 such a date
no longer round-tripped through JSON as it did with chrono. Display now
formats with the same %Y-%m-%d; for years 0 to 9999 the output is
unchanged.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 22:55
@jeremy jeremy added the bug Something isn't working label Nov 19, 2026
@github-actions github-actions Bot added the rust Rust SDK label Nov 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

There are no active review issues for the date-formatting change.

No open issues 🎉

What changed in this PR

Fixes Rust Date formatting after the jiff migration in #1106 so dates with negative years can round-trip through text and JSON.

Changes:

  • Formats dates with %Y-%m-%d, matching the parser.
  • Adds parsing and serde round-trip tests covering negative years, year zero, and calendar boundaries.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
rust/​basecamp-sdk/​src/​types.rs Aligns date display with parsing and adds boundary round-trip tests.

Review effort: Balanced

@jeremy
jeremy merged commit 0e16437 into main Nov 19, 2026
53 checks passed
@jeremy
jeremy deleted the fix/date-display-round-trip branch November 19, 2026 23:06
jeremy added a commit that referenced this pull request Nov 20, 2026
Prepares SDK v0.38.0 with `make bump VERSION=0.38.0`: version lines across Go, TypeScript, Ruby, Python, Kotlin, Swift and Rust, their lockfiles, and MIGRATING.md's Unreleased section promoted to v0.38.0.

Release scope since v0.37.0:
- #1106 Replace chrono with jiff in the Rust SDK (breaking, so a minor before 1.0)
- #1107 Print a Rust date the way it is read, so a year before 0 reads back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rust Rust SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants